<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Evan
 * Date: 12-10-3
 * Time: 上午11:55
 * To change this template use File | Settings | File Templates.
 */
class LoginController extends Jwawa_BaseController
{
    public function verifyAction()
    {
        $param = $this->getJsonDataFromReq();
        $login_accounts = new Model_Sso_LoginAccoutsDao();
        $login_name = strtolower(trim($param['login_name']));
        $login_pwd = strtolower(trim($param['login_pwd']));
        $login_account = $login_accounts->verify($login_name, $login_pwd);

        if($login_account == null){
            throw new Jwawa_BusinessException("LOGIN_FAILURE_USER_NOT_EXIST");
        }

        $userActionCodeList = Model_Cfg_Action::findUserActionCodeList($login_account["id"]);
        $userActionCodeMap = array();
        foreach($userActionCodeList as $userActionCode){
            $userActionCodeMap[$userActionCode] = true;
        }

        $session_bag = $this->getSessionBag();
        $session_bag->setLoginAccountId($login_account["id"]);
        $session_bag->setLoginName($login_account["login_name"]);
        $session_bag->setEmployeeName($login_account["employee_name"]);
        $session_bag->setUserActionCodeMap($userActionCodeMap);

        $json = Zend_Json::encode(new Jwawa_ResponseBaseDto('/home/index'));
        echo  $json;
    }
}
